package com.example.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.stereotype.Component;
import org.springframework.util.StringValueResolver;

/**
 *  实现接口得到回调，得到spring底层组件对象
 *  注入spring底层bean是使用后置处理器实现的
 */
@Component
public class Bean implements ApplicationContextAware, BeanNameAware, EmbeddedValueResolverAware {

    /**
     *
     * @param applicationContext  ioc容器
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println(applicationContext);
    }

    /**
     * @param name spring容器为当前bean定义的名字
     */
    @Override
    public void setBeanName(String name) {
        System.out.println("当前bean定义的id是 " + name);
    }

    /**
     *
     * @param resolver 字符串解析器
     */
    @Override
    public void setEmbeddedValueResolver(StringValueResolver resolver) {
        String s = resolver.resolveStringValue("hello ${os.name} #{1+2}");
        System.out.println(s);
    }
}


